package dormouse.vfs.ui.actions;

import org.jdesktop.application.Application;
import org.jdesktop.application.ResourceManager;
import org.jdesktop.application.ResourceMap;

import dormouse.Dormouse;
import dormouse.DormouseView;

/**
 * This class serves as a template for file tasks that show a particular
 * location. Subclasses typically show the location for an operating-system
 * specific location such as the "Documents" directory, the "Music" directory, etc.
 */
public abstract class AbstractShowLocationTask extends AbstractFileTask {

	protected String locationKey = null;

	/**
	 * Constructor
	 * 
	 * @param app
	 *            The parent application
	 * @param locationKey
	 *            The key in the resource map to the location you want to use.
	 *            These are found in the Dormouse.properties file.
	 */
	public AbstractShowLocationTask(Application app, String locationKey) {
		super(app);
		this.locationKey = locationKey;
	}

	/**
	 * This method fetches the location used by the action.
	 * 
	 * @return
	 */
	public String getLocation() {
		Dormouse exp = (Dormouse) this.getApplication();
		ResourceMap rm = exp.getContext().getResourceMap();
		ResourceManager rmgr = exp.getContext().getResourceManager();
		return rm.getString(this.locationKey + "." + rmgr.getPlatform(),
				System.getProperty("user.home"));
	}

	@Override
	protected Object doInBackground() throws Exception {
		if (!this.isCancelled()) {
			String location = getLocation();
			DormouseView view = (DormouseView) Dormouse.getApplication()
					.getMainView();
			view.setLocation(location);
		}
		return null;
	}
	
	@Override
	public String[] getFileExtensions() {
		return null;
	}
}
